﻿<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>学生列表</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<%--
<link href="${pageContext.request.contextPath }/css/.css" type=text/css rel=stylesheet>
<link href="${pageContext.request.contextPath }/css/.css" type=text/css rel=stylesheet>
--%>
<link rel="stylesheet" href="../jquery/jquery.datepick.css" type="text/css">
<script type="text/javascript" src="${pageContext.request.contextPath }/js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/jquery/jquery-1.4.2.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/jquery/jquery.datepick.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/jquery/jquery.datepick-zh-CN.js"></script>
<style type="text/css">
	a{ text-decoration: none; }
	a:link { color: blue }               /* 未被访问的链接 */
	a:visited { color: blue }            /* 已被访问过的链接 */ 
</style>
<script language=javascript>
	$(function(){
		//使用class属性处理  'yy-mm-dd' 设置格式"yyyy/mm/dd"
		$('#nextDate').datepick({dateFormat: 'yy-mm-dd'}); 
	});
	
	function delOne(studentId){
		var sure = window.confirm("确定删除吗？");
		if(sure){
			window.location.href="${pageContext.request.contextPath}/customer/removeCustomer.action?studentId="+studentId;
		}
	};
	function put(studentId){
		var sure = window.confirm("确定拉入公海吗？\n拉入“公海”后“下次联系日期”将清空！");
		if(sure){
			window.location.href="${pageContext.request.contextPath}/customer/putCommon.action?studentId="+studentId;
		}
	};
	function goToPage(goPage){
		//因为js代码有要去的页码  可以在js中直接判断
		if(goPage<1){
			/* alert("当前已经是第一页了  不能上一页"); */
			return ; 
		}
		//获得最大页数
		var totalPage = '${pageBean.totalPage}';
		if(goPage>totalPage){ //当前页大于 最大页数
			/* alert("当前已经是最后一页了  不能下一页"); */
			return ; 
		}
		
		
		//函数的参数为 将要访问的页码 只需要条件 即可 
		//而条件在表单当中  我如果将页码也放入了表单  只需要提交表单 那条件有了 页码也有了
		//获得隐藏域 并且赋值即可
		$("#pageNumberId").val(goPage);
		//提交表单  先获得表单 再提交即可
		$("#customerForm").submit();
	};
	/* function to_page(page){
		if(page){
			$("#page").val(page);
		}
		document.customerForm.submit();
		
	} */
	
	/*全选JS*/
    function CheckAll(thisform){
	    for (var i=0;i<thisform.elements.length;i++){
	    	var e = thisform.elements[i];
	    	if (e.Name != "chkAll"&&e.disabled!=true)
	    	e.checked = thisform.chkAll.checked;
	    }
    };
	
    /*判断是否选空*/
    function judge(){
	    var arrayid = new Array();
	    
	    $('input[name="ids"]:checked').each(function(){arrayid.push($(this).val());});
	    
	    if(arrayid.length==0){
		    alert("无学生选中！");
		    event.preventDefault(); // 兼容标准浏览器
		    window.event.returnValue = false; // 兼容IE6~8
	    }else if(arrayid.length > 0) {
	    	var msg = "您确定要删除选中的学生吗？";   
	        if (confirm(msg)==true){   
	            var allcheckbox = "";
	            var becheckbox = "";
	            $("input[name=ids]").each(function(){ //遍历table里的全部checkbox
	                allcheckbox += $(this).val() + ","; //获取所有checkbox的值
	                if($(this).attr("checked")) //如果被选中
	                    becheckbox += $(this).val() + ","; //获取被选中的值
	            });

	            if(becheckbox.length > 0) //如果获取到
	                becheckbox = becheckbox.substring(0, becheckbox.length - 1); //把最后一个逗号去掉
	                window.location = "${pageContext.request.contextPath}/customer/deleteAll.action?checkTnum="+becheckbox;
	        }
	    }
    };
    
    function judgeCommon(){
	    var arrayid = new Array();
	    
	    $('input[name="ids"]:checked').each(function(){arrayid.push($(this).val());});
	    
	    if(arrayid.length==0){
		    alert("无学生选中！");
		    event.preventDefault(); // 兼容标准浏览器
		    window.event.returnValue = false; // 兼容IE6~8
	    }else if(arrayid.length > 0) {
	    	var msg = "您确定要将选中的学生拉入公海吗？";   
	        if (confirm(msg)==true){   
	            var allcheckbox = "";
	            var becheckbox = "";
	            $("input[name=ids]").each(function(){ //遍历table里的全部checkbox
	                allcheckbox += $(this).val() + ","; //获取所有checkbox的值
	                if($(this).attr("checked")) //如果被选中
	                    becheckbox += $(this).val() + ","; //获取被选中的值
	            });

	            if(becheckbox.length > 0) //如果获取到
	                becheckbox = becheckbox.substring(0, becheckbox.length - 1); //把最后一个逗号去掉
	                window.location = "${pageContext.request.contextPath}/customer/putCommonAll.action?checkTnum="+becheckbox;
	        }
	    }
    };
    
    // 实时修改
    function update(id , c , num , page) {
    	//alert(c.value);
    	
    	if(num == 2){
    		if(c.value === "男"){
    			c.value = 0;
    			//alert(c.value);
    		}else if(c.value === "女"){
    			c.value = 1;
    			//alert(c.value);
    		}else{
    			alert("输入错误！");
    			goToPage(page);
    			return;
    		}
    	}
    	if(num == 3){
    		
    		if(/^\d{1,2}$/.test(c.value) ){
    			//alert(c.value);
    		}else{
    			alert("输入错误！");
    			goToPage(page);
    			return;
    		}
    	}
		if(num == 4 || num == 5){
    		
    		if(/^\d{1,12}$/.test(c.value) ){
    			//alert(c.value);
    		}else{
    			alert("输入错误！");
    			goToPage(page);
    			return;
    		}
    	}

    	

    	$.post(
    		"${pageContext.request.contextPath}/customer/instantaneousEdit",
    		{"studentId":id , "str":c.value , "n":num },
    		function(){
    			//window.location.href = "${pageContext.request.contextPath}/customer/findAllCustomer";
    			goToPage(page);
    		}
    		
    	);
    }

</script>
<meta content="MSHTML 6.00.2900.3492" name=GENERATOR>
</head>
<body>
	<h2>学生列表</h2>
	<s:form action="findAllCustomer" namespace="/customer" id="customerForm" name="customerForm">
		<p>学生总人数：${pageBean.totalRecord}</p>
		<table cellSpacing=0 cellPadding=0 width="98%" border=0>
		<TBODY>
		<tr>
		<table borderColor=#cccccc cellSpacing=0 cellPadding=0 width="100%" align=center border=0>
		<TBODY>
			<tr>
				<td height=25>
					<table cellSpacing=0 cellPadding=2 border=0>
						<TBODY>
							<tr>
								
								<td>学生查询：</td>
								<td>
									<s:textfield name="select" class="textbox" id="sChannel2" style="WIDTH: 80px" maxLength="50" />
								</td>
								
								
								<td>所属教师 ：</td>
									<td>
										<s:select name="affiliatedTeacher.userId" list="affiliatedTeachers" listKey="userId" listValue="userName"
										 headerKey="" headerValue="所有" class="textbox" id="sChannel2"></s:select>
									</td>
								
								<!-- 页码的隐藏域 -->
								<input type="hidden" name="pageNumber" value="1" id="pageNumberId"/>
								
								<td><s:submit value=" 筛选 "/></td>
							
								<td></td>
								<%-- <s:iterator value="customers" var="c"> --%>
								<td><input type="button" value="删除" onclick="judge()" /></td>
								<td><input type="button" value="拉入公海" onclick="judgeCommon()" /></td>
							
							</tr>
						</TBODY>
					</table>
				</td>
			</tr>

			<tr>
				<td>
					<table >
					<TBODY>
						<tr style="FONT-WEIGHT: bold; FONT-STYLE: normal; BACKGROUND-COLOR: #eeeeee; TEXT-DECORATION: none">
							<!-- <td>编号</td> -->
							<td>选中<s:checkbox name="chkAll" onclick="CheckAll(this.form)" /></td>
							<td>学生ID</td>
							<td>学生姓名</td>
							<td>性别</td>
							<td>年龄</td>
							<td>爸爸电话</td>
							<td>妈妈电话</td>
							<td>跟进状态</td>
							<td>下次联系日期</td>
							<td>家庭住址</td>
							<td>备注</td>
							<td>负责员工</td>
							<td>操作</td>
						</tr>
						
						<!-- customers -->
						<%-- <s:iterator value="customers" var="c">  --%>
						
						
						<c:forEach items="${pageBean.data}" var="customer" varStatus="status">

						<tr style="FONT-WEIGHT: normal; FONT-STYLE: normal; BACKGROUND-COLOR: white; TEXT-DECORATION: none">
						
						
							<%-- <td>${status.count} </td> --%>
							<td>
								<%-- <s:checkbox name="ids" value="false" fieldValue="%{customer.studentId }" /> --%>
								<input name="ids" type="checkbox" value="${customer.studentId }" />
							</td>
							<%-- <td>${customer.studentId }</td>
							<td>${customer.studentName }</td>
							<td>${customer.studentSex ==0 ? "男" : "女"}</td>
							<td>${customer.studentAge }</td>
							<td>${customer.phone1 }</td>
							<td>${customer.phone2 }</td>
							<td>${customer.followUp }</td>
							<td>${customer.nextDate }</td>
							<td>${customer.address }</td>
							<td>${customer.remark }</td>
							<td>${customer.affiliatedTeacher.userName }</td>  --%>
							
   
                            <td>${customer.studentId }</td>
							<td>
								<%-- ${customer.studentName } --%>
								<input type="text" name="studentName" id="studentName" value='${customer.studentName }' class=""  onChange="update('${customer.studentId}' , this , 1 , ${pageBean.pageNumber})"  size="5px" /> 
							</td>
							<td>
								<%-- ${customer.studentSex ==0 ? "男" : "女"} --%>
								<input type="text" name="" id="studentSex" value='${customer.studentSex ==0 ? "男" : "女"}' class=""  onChange="update('${customer.studentId}' , this , 2 , ${pageBean.pageNumber})" size="1px"/>
							</td>
							<td>
								<%-- ${customer.studentAge } --%>
								<input type="text" name="" id="studentAge" value='${customer.studentAge }' class=""  onChange="update('${customer.studentId}' , this , 3 , ${pageBean.pageNumber})" size="1px"/> 
							</td>
							<td>
								<%-- ${customer.phone1 } --%>
								<input type="text" name="" id="phone1" value='${customer.phone1 }' class=""  onChange="update('${customer.studentId}' , this , 4 , ${pageBean.pageNumber})" size="10px"/> 
							</td>
							<td>
								<%-- ${customer.phone2 } --%>
								<input type="text" name="" id="phone2" value='${customer.phone2 }' class=""  onChange="update('${customer.studentId}' , this , 5 , ${pageBean.pageNumber})" size="10px"/> 
							</td>
							<td>
								<%-- ${customer.followUp } --%>
								<a href="${pageContext.request.contextPath}/customer/editUICustomer?studentId=${customer.studentId}">
									${customer.followUp }&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
								</a>
							</td>
							<td>
								<%-- ${customer.nextDate } --%>
								<%-- <s:textfield name="nextDate" class="textbox" id="nextDate" readonly="true" style="width: 180px" maxLength="50" /> --%>
								<input type="text" name="" id="nextDate" value="${customer.nextDate }" onChange="update('${customer.studentId}' , this , 6 , ${pageBean.pageNumber})" size="20px" readonly="true" />
							</td>
							
							
							<td>
								<%-- ${customer.address } --%>
								<input type="text" name="" id="address" value='${customer.address }' class=""  onChange="update('${customer.studentId}' , this , 7 , ${pageBean.pageNumber})" size="15px"/> 
							</td>
							<td>
								<%-- ${customer.remark } --%>
								<input type="text" name="" id="remark" value='${customer.remark }' class=""  onChange="update('${customer.studentId}' , this , 8 , ${pageBean.pageNumber})" size="15px"/> 
								
							</td>
							
							
							<td>${customer.affiliatedTeacher.userName }</td>
						 
						 
							<td>
								<a href="${pageContext.request.contextPath}/customer/editUICustomer?studentId=${customer.studentId}">
									修改
								</a>
								
								&nbsp;&nbsp;
								<a href="javascript:delOne('${customer.studentId}')">删除</a>
							
								&nbsp;&nbsp;
								<a href="javascript:put('${customer.studentId}')">拉入公海</a>
							</td>
						</tr>
						<!-- </form> -->
						<%-- </s:iterator> --%>
						</c:forEach>
						
						
					</TBODY>
					</table>
				</td>
			</tr>
		</TBODY>
		</table>
		</tr>
		</TBODY>
		</table>
		<div style="height: 20px; text-align: right; margin-top:10px; font-size: 17px;" >
			共[<b>${pageBean.totalRecord}</b>]条记录&nbsp;,&nbsp;第[<b>${pageBean.pageNumber}</b>]页
			&nbsp;&nbsp;
			[<a href="javascript:void(0)" onclick="goToPage(${pageBean.pageNumber-1})">上一页</a>]
			<b>
				<%-- 前五后四动态条 前四后五动态条 其目的主要是保证数据一直在中间 不发生变化 --%>
				<c:forEach begin="${pageBean.start}" end="${pageBean.end}" step="1" var="num">
				<%-- <c:forEach begin="1" end="${pageBean.totalPage}" step="1" var="num"> --%>
					<a href="javascript:void(0)" onclick="goToPage(${num})" >
						<font ${num == pageBean.pageNumber ? "color='red'" : ""}>&nbsp;${num}</font>
					</a>
				</c:forEach>
			</b>&nbsp;
			[<a href="javascript:void(0)" onclick="goToPage(${pageBean.pageNumber+1})">下一页</a>]
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		</div>				
	</s:form>
</body>
</html>
